﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using System.Data.Services.Common;
using System.Data.Services.Providers;

namespace VsxFactory.Repository.StrategiesGallery
{
#if DEBUG
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
#endif

    public class Strategies : DataService<StrategyDataContext>, IServiceProvider
    {
        private PackageStreamProvider provider;

        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.UseVerboseErrors = true;
            config.SetEntitySetAccessRule("*", EntitySetRights.All);           
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }

        private PackageStreamProvider Provider
        {
            get
            {
                if (provider == null)
                    provider = new PackageStreamProvider(this, this.CurrentDataSource);
                return provider;
            }
        }

        public object GetService(Type serviceType)
        {
            if (serviceType == typeof(IDataServiceStreamProvider))
            {
                return Provider;
            }
            return null;
        }
    }
}
